home *** CD-ROM | disk | FTP | other *** search
- Path: colossus.holonet.net!russell
- From: russell@news.mdli.com (Russell Blackadar)
- Newsgroups: comp.lang.c++
- Subject: Re: Struct as default arg?
- Date: 25 Jan 1996 23:46:35 GMT
- Organization: HoloNet National Internet Access System: 510-704-1058/modem
- Message-ID: <4e94or$5nu@colossus.holonet.net>
- References: <rplDLrDFr.35K@netcom.com>
- NNTP-Posting-Host: jubal.mdli.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Robert Laudati (rpl@netcom.com) wrote:
- : I would like to use a structure as a default args as follows:
-
- : typedef struct { double x; double y; } Point;
-
- : int Write( int n, char *s, Point p={0.0,0.0} );
-
- Try this:
- const Point pconst = {0.0,0.0};
- int Write( int n, char *s, Point p = pconst );
-
- BTW, I'd recommend const Point& for the third arg, instead of Point.
- This avoids copying the struct, which presumably you don't need to
- do (you're just outputting it).
-
- Also, in C++, you can write
-
- struct Point { double x; double y; };
-
- which IMO is preferable to a typedef, stylistically.
- --
- Russell Blackadar, russell@mdli.com
-